<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 编写函数 sortByAge(users) 获得对象数组的 age 属性，并根据 age 对这些对象数组进行排序。
        let arr = [
            { name: "John", age: 25 },
            { name: "Pete", age: 30 },
            { name: "Mary", age: 28 }
        ];
        // let newArr = arr.map(function(obj,age){

        // })
        
           function sortByAge(user){
            let newArr = user.sort((a,b)=>a.age-b.age);
            return newArr;
           }
           	
            
        console.log(sortByAge(arr)); 
        

        
        
        
        console.log(arr[0].name); // John
        console.log(arr[1].name); // Mary
        console.log(arr[2].name); // Pete
    </script>
</body>

</html>